Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support complex64 tensor - real scalar operations (like numpy does) #629

Merged

Conversation

AngelEzquerra
Copy link
Contributor

@AngelEzquerra AngelEzquerra commented Feb 28, 2024

It is always possible to operate on a Complex64 tensor with a real scalar without loss of precision, so we allow it without explicit type conversion.

This is supported by numpy, and makes complex tensor arithmetic more convenient to use (by avoiding having to explicitly make many obvious conversions to complex).

As an example, assuming t is a Tensor[Complex64], this let's you write expressions such as:

(complex(1.0 / sqrt(2.0)) *. t -. complex(1.0)) /. complex(t.size.float)

as follows:

((1.0 / sqrt(2.0)) *. t -. 1.0) /. t.size

which is much easier to understand while being equally safe.

It is always possible to operate on a Complex64 tensor with a real scalar without loss of precision, so we allow it without explicit type conversion.

This is supported by numpy, and makes complex tensor arithmetic more convenient to use (by avoiding having to explicitly make many obvious conversions to complex).

As an example, assuming `t` is a Tensor[Complex64], this let's you write expressions such as:
```
(complex(1.0 / sqrt(2.0)) *. t -. complex(1.0)) /. complex(t.size.float)
```

as follows:
```
((1.0 / sqrt(2.0)) *. t -. 1.0) /. t.size
```

which is much more easier to understand while being equally safe.
@Vindaar
Copy link
Collaborator

Vindaar commented Mar 2, 2024

Nice, I agree that's useful. I barely use complex numbers in my code, so I never much stumbled over it.

@Vindaar Vindaar merged commit d7b1fff into mratsim:master Mar 2, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants